<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>DonReY Framework :: My first project !</title>
<link rel='stylesheet' type='text/css' href='/Documentation/DonReY.css' media='screen' />
</head>
<body>
<a href="/documentation/donrey.html" title="DonReY Framework Documentation">DonReY Framework Documentation</a> &raquo; <a href="/documentation/getting-started.html" title="Getting Started">Getting Started</a> &raquo; My first project !
<hr />
	<h2>My First Project</h2>

	<p>DonReY uses the <em>Front Controller</em> design pattern as it&#8217;s principle of operation. All <span class="caps">URL</span> are directed to the <strong>index.php</strong> file, which handles loading of the framework&#8217;s core, and then loads and uses whatever modules it considers appropirate.</p>

	<p>For example, a little website that only displays a text would have this as it&#8217;s index.php file:  </p>

<pre class="php"><span class="kw2">&lt;?php</span>
<span class="co1">// include the DonReY Framework</span>
<span class="kw1">require</span> <span class="st0">&quot;../DonReY_BootStrap.php&quot;</span><span class="sy0">;</span>
&nbsp;
<span class="co1">// load the &quot;test&quot; module and tells it to &quot;do something&quot; :)</span>
core<span class="sy0">::</span><span class="me2">test</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">-&gt;</span> <span class="me1">do_Something</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span> <span class="co1">// outputs: Hello World, I'm a DonReY Framework Project !</span>
&nbsp;
<span class="co1">// cleanup after execution</span>
core<span class="sy0">::</span><span class="me2">unload_All_Modules</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span>
&nbsp;
<span class="co1">// Debugging with DonReY is very easy, just type:</span>
dd<span class="br0">&#40;</span><span class="nu0">1337</span><span class="sy0">,</span> <span class="st0">&quot;Hello World, I'm a constant&quot;</span><span class="br0">&#41;</span><span class="sy0">;</span> <span class="co1">// This should send the debug string or variable/constant to any registered debugger</span></pre>

	<p>See this working example <a href="http://examples.donrey.net/entry-point.php">here</a>.</p>

	<p>The BootStrap file is a simple way to create a minimal configuration for your project.<br />
Such a file is provided with the framework, the only things that need adjusting are the paths to where the framework is located ( can be anywhere on the server )</p>

	<p>Here&#8217;s an example bootstrap file:</p>

<pre class="php"><span class="kw2">&lt;?php</span>
<span class="co4">/**
 * DonReY Framework 2012 :: BootStrap Initialization File
 * This file should be copied in project root ( not the &quot;htdocs&quot; ), and it contains all required functionality to initialize and load DonReY framework
 * - Path initialization
 * - Required constants
 * - DonReY Core inclusion
 * - Extra required files inclusion
 */</span>
&nbsp;
<span class="co1">//= debugging the app =//</span>
<span class="kw3">ini_set</span><span class="br0">&#40;</span><span class="st_h">'display_errors'</span><span class="sy0">,</span><span class="st_h">'stdout'</span><span class="br0">&#41;</span><span class="sy0">;</span>
<span class="kw3">error_reporting</span><span class="br0">&#40;</span><span class="sy0">-</span><span class="nu0">1</span><span class="br0">&#41;</span><span class="sy0">;</span>
<span class="co1">//error_reporting(E_ERROR | E_WARNING | E_PARSE | E_NOTICE);</span>
<span class="co1">//error_reporting(0); // framework handles error capturing, no need to display them on screen</span>
&nbsp;
<span class="co1">//*** Set proper paths for the DonReY framework below this line ***//</span>
&nbsp;
<span class="co1">// Location of external libraries, which might be needed by some modules or the application</span>
<span class="kw3">define</span><span class="br0">&#40;</span><span class="st_h">'LIB_PATH'</span>	<span class="sy0">,</span> <span class="kw3">realpath</span><span class="br0">&#40;</span><span class="st_h">'/home/library'</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span>
&nbsp;
<span class="co1">// Location where DonReY directory structure is: &quot;core.php&quot;, the &quot;modules&quot; directory and everything else</span>
<span class="kw3">define</span><span class="br0">&#40;</span><span class="st_h">'CORE_PATH'</span>	<span class="sy0">,</span> <span class="kw3">realpath</span><span class="br0">&#40;</span><span class="st_h">'/home/library/donrey2012'</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span>
&nbsp;
<span class="co1">// Location where your Application directory structure is: (usually where &quot;index.php&quot; is, or one level above if &quot;htdocs&quot; ( the web root ) is inside this directory)</span>
<span class="kw3">define</span><span class="br0">&#40;</span><span class="st_h">'APP_PATH'</span>	<span class="sy0">,</span> <span class="kw3">realpath</span><span class="br0">&#40;</span>__DIR__<span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span> <span class="co1">// this dir, where the app root path is ( outside htdocs )</span>
&nbsp;
<span class="co1">// This helps access other libraries that may be used by DonReY ( for example - FirePHP, Smarty or GeSHi  )</span>
<span class="kw3">set_include_path</span><span class="br0">&#40;</span><span class="kw3">implode</span><span class="br0">&#40;</span>PATH_SEPARATOR<span class="sy0">,</span> <span class="kw3">array</span><span class="br0">&#40;</span>
	<span class="kw3">realpath</span><span class="br0">&#40;</span>LIB_PATH<span class="br0">&#41;</span><span class="sy0">,</span> <span class="co1">// libraries path ( usually contains other 3rd party libraries which need to be loaded by DonReY )</span>
	<span class="kw3">realpath</span><span class="br0">&#40;</span>APP_PATH<span class="sy0">.</span> <span class="st_h">'/library'</span><span class="br0">&#41;</span><span class="sy0">,</span> <span class="co1">// extra libraries used just for this application ( might not exist )</span>
	<span class="kw3">get_include_path</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">,</span>
<span class="br0">&#41;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span>
&nbsp;
<span class="co1">//*** Do not modify anything below this line, this section is part of the framework ***//</span>
&nbsp;
<span class="co1">// include DonReY Core</span>
<span class="kw1">require_once</span><span class="br0">&#40;</span>CORE_PATH<span class="sy0">.</span> <span class="st_h">'/core.php'</span><span class="br0">&#41;</span><span class="sy0">;</span> <span class="co1">// the DonReY Core. Everything starts here</span>
<span class="kw1">require_once</span><span class="br0">&#40;</span>CORE_PATH<span class="sy0">.</span> <span class="st_h">'/core_exceptions_english.php'</span><span class="br0">&#41;</span><span class="sy0">;</span> <span class="co1">// change language if -really- necessary</span>
&nbsp;
<span class="co1">// load configuration and initialize core</span>
core<span class="sy0">::</span>_init<span class="br0">&#40;</span>APP_PATH<span class="sy0">.</span> <span class="st_h">'/project-config.xml'</span><span class="br0">&#41;</span><span class="sy0">;</span> <span class="co1">// default configuration should be in the same path as this bootstrap file</span></pre>

	<p>You are free to change the BootStrap in any way you want, but make sure the constants <span class="caps">LIB</span>_PATH, <span class="caps">CORE</span>_PATH and <span class="caps">APP</span>_PATH are set to their proper locations, and core.php and core_exceptions_english.php (or other language ) are included. There is no need to include external code here or in index.php, the Core has a library loader that will include code on demand (when a module or your application actually needs it)</p>

	<p><strong>It is absolutely necessary for a configuration file to exist for the core::_init method !</strong></p>

	<p>The Project Configuration file ( project-config.xml ) contains settings for the core and modules, and can contain arbitrary data for the application itself:</p>

<pre class="xml"><span class="sc3"><span class="re1">&lt;?xml</span> <span class="re0">version</span>=<span class="st0">&quot;1.0&quot;</span> <span class="re0">encoding</span>=<span class="st0">&quot;UTF-8&quot;</span><span class="re2">?&gt;</span></span>
<span class="sc-1">&lt;!-- This is your most basic configuration file, it includes  --&gt;</span>
<span class="sc3"><span class="re1">&lt;config<span class="re2">&gt;</span></span></span>
	<span class="sc3"><span class="re1">&lt;core</span> <span class="re0">debug</span>=<span class="st0">'all'</span> <span class="re0">outputoncrash</span>=<span class="st0">'show'</span><span class="re2">&gt;</span></span><span class="sc-1">&lt;!-- debug: disabled / internal / external / all ; outputoncrash: hide / show --&gt;</span>
		<span class="sc-1">&lt;!-- Set the files where external libraries are located, so the core knows from where to load them when a class is required --&gt;</span>
		<span class="sc3"><span class="re1">&lt;libs<span class="re2">&gt;</span></span></span>
			<span class="sc-1">&lt;!-- name is the library's primary &quot;class&quot;, content is the path ( relative or absolute ) --&gt;</span>
			<span class="sc3"><span class="re1">&lt;FirePHP</span> <span class="re0">rel</span>=<span class="st0">'LIB_PATH'</span><span class="re2">&gt;</span></span>/FirePHP/FirePHP.class.php<span class="sc3"><span class="re1">&lt;/FirePHP<span class="re2">&gt;</span></span></span>
		<span class="sc3"><span class="re1">&lt;/libs<span class="re2">&gt;</span></span></span>
&nbsp;
		<span class="sc-1">&lt;!-- All configuration inside this element is being sent to modules. Only the modules themselves know what to do with it! --&gt;</span>
		<span class="sc3"><span class="re1">&lt;modules<span class="re2">&gt;</span></span></span>
			<span class="sc-1">&lt;!-- A test module that does nothing, used just to test the module loading system --&gt;</span>
			<span class="sc3"><span class="re1">&lt;test<span class="re2">&gt;</span></span></span>
			<span class="sc3"><span class="re1">&lt;/test<span class="re2">&gt;</span></span></span>
&nbsp;
			<span class="sc-1">&lt;!-- The debugger module which uses a &quot;driver&quot; to function. In this case, FirePHP, which outputs into browser's console --&gt;</span>
			<span class="sc-1">&lt;!-- There are two important parameters to the module element: &quot;alias&quot; and &quot;autoload&quot;</span>
<span class="sc-1">			     &quot;alias&quot; gives this module an unique name, which can be accessed from the code with: core::{this-alias}();</span>
<span class="sc-1">			       In this case: core::firedebug()</span>
<span class="sc-1">			     &quot;autoload&quot; makes the module load immediatly at initialization time ( when Core reads this config file ),</span>
<span class="sc-1">			     and is generally used for modules which need to be always present ( like this Debug module )</span>
<span class="sc-1">			     Otherwise, the core loads a module only on first use ( lazy loading ) --&gt;</span>
			<span class="sc3"><span class="re1">&lt;debug</span> <span class="re0">alias</span>=<span class="st0">'firedebug'</span> <span class="re0">autoload</span>=<span class="st0">'true'</span><span class="re2">&gt;</span></span>
				<span class="sc-1">&lt;!-- The &quot;register&quot; keyword makes the Debug module to use this driver as debug output for the Core (in this case, under the ID &quot;fb&quot;),</span>
<span class="sc-1">				     so all errors and debug messages will be routed to this driver (in this case, displaying debug information in the console)</span>
<span class="sc-1">				     See the documentation for the Core and the Debug Module for more information --&gt;</span>
				<span class="sc3"><span class="re1">&lt;driver</span> <span class="re0">register</span>=<span class="st0">'fb'</span><span class="re2">&gt;</span></span>FirePHP<span class="sc3"><span class="re1">&lt;/driver<span class="re2">&gt;</span></span></span>
			<span class="sc3"><span class="re1">&lt;/debug<span class="re2">&gt;</span></span></span>
&nbsp;
		<span class="sc3"><span class="re1">&lt;/modules<span class="re2">&gt;</span></span></span>
	<span class="sc3"><span class="re1">&lt;/core<span class="re2">&gt;</span></span></span>
	<span class="sc-1">&lt;!-- Other configuration might exist here, which is not directly related to DonReY or used by any modules</span>
<span class="sc-1">	     Any element in this config file can be accessed with core::$CFG, and in this case: core::$CFG-&gt; something</span>
<span class="sc-1">	     Core loads this config file as a SimpleXMLElement, and passes the relevant pieces to modules --&gt;</span>
	<span class="sc3"><span class="re1">&lt;something<span class="re2">&gt;</span></span></span>
		Only the application knows what this is.
	<span class="sc3"><span class="re1">&lt;/something<span class="re2">&gt;</span></span></span>
<span class="sc3"><span class="re1">&lt;/config<span class="re2">&gt;</span></span></span></pre>

	<p><em>See the &#8220;Examples&#8221; directory for several working examples.</em></p>
</body>
</html>
<!-- http://www.donrey.net/Documentation - Built with DonReY Framework http://www.donrey.net/ - Powered by PHP, MySQL, JavaScript -->